#ifndef _MY_CEGUI_H
#define _MY_CEGUI_H

#include <CEGUI/CEGUI.h>
#include "Ogre.h"
#include "OgreCEGUIRenderer.h"
#include "OgreCEGUIResourceProvider.h"
#include "Helper.h"
#include "GameSceneManager.h"
#include "GameSystemManager.h"
#include "TerrainSystem.h"
#include "frmPaging.h"
#include "frmMenuBar.h"
#include "frmTerrain.h"
#include "frmPhysics.h"
#include "frmObjects.h"
#include "frmScene.h"

class GameSceneManager;
class GameSystemManager;
class TerrainSystem;
class frmPaging;
class frmMenuBar;
class frmTerrain;
class frmPhysics;
class frmObjects;
class frmScene;

using namespace Ogre;

class GUISystem
{
private:
	unsigned short currentGUI;
	
	static RenderWindow *mWindow;
	static SceneManager *mSceneMgr;
	static GameState *gameState;
	static CEGUI::Window* mainWindow;
	
	//Game GUI Forms
	static frmMenuBar *mfrmMenuBar;
	static frmTerrain *mfrmTerrain;
	static frmPhysics *mfrmPhysics;
	static frmObjects *mfrmObjects;
	static frmScene *mfrmScene;
	static frmPaging *mfrmPaging;

	

	CEGUI::MouseButton convertOISMouseButtonToCegui(int);
	
	void setStaticImageObject(Ogre::String,Ogre::String,Ogre::String);

	CEGUI::Window* getMainWindow();

	bool windowMoved(const CEGUI::EventArgs&);

	//GUI Event subscriber
	bool subscribeEvents();

	//Terrain GUI Events
	//bool evtTerrainNew_click(const CEGUI::EventArgs& e);
	//bool evtTerrainDelete_click(const CEGUI::EventArgs& e);
	//bool evtTerrainRefresh_click(const CEGUI::EventArgs& e);
	//bool evtTerrainGenerate_click(const CEGUI::EventArgs& e);
	//bool evtTerrainList_click(const CEGUI::EventArgs& e);
	//bool evtTerrainClose_click(const CEGUI::EventArgs& e);

	//Multiplayer GUI Events
	bool evtClientConnect_click(const CEGUI::EventArgs& e);
	bool evtClientQuit_click(const CEGUI::EventArgs& e);
	bool evtClientClose_click(const CEGUI::EventArgs& e);

	//MenuBar/Multiplayer

	//Physics
	//bool evtPhysicsClose_click(const CEGUI::EventArgs& e);
	//bool evtPhysicsCreate_click(const CEGUI::EventArgs& e);
	//bool evtPhysicsDestroy_click(const CEGUI::EventArgs& e);
	//bool evtPhysicsStart_click(const CEGUI::EventArgs& e);
	//bool evtPhysicsStop_click(const CEGUI::EventArgs& e);
	//bool evtPhysicsGenerateTerrainActor_click(const CEGUI::EventArgs& e);

public:
	
	GUISystem();
	~GUISystem();

	static CEGUI::Renderer* mGUIRenderer;
	static CEGUI::System* mGUISystem;

	void updatePagedObjects();
	void updateGameObjects();
	void updateMouseMoved(int x, int y);
	void updateMouseButtonDown(unsigned int button);
	void updateMouseButtonUp(unsigned int button);
	void updateKeyboardKeyPressed(OIS::KeyEvent evt);
	void updateKeyboardKeyReleased(OIS::KeyEvent evt);

	void fillGUIFromConfig();

	//void UpdateState();
	void destroyGUI();

	void hideCursor();
	void showCursor();
	void updateObjectsWindow();
	void setupGUI();

	CEGUI::Window* getElement(const char*);
	void showLoader(bool show);
	//void setProgressBarValue(float value);

	const char* EditBoxToChr(CEGUI::String);
	float EditBoxToFloat(std::string EditBoxName);
	bool CheckBoxToBool(std::string checkBoxName);
	void GUISystem::selectItemCombobox(std::string cmbName, std::string cmbItem);

	CEGUI::Window* addImageToControl(Ogre::String imageName,Ogre::String windowName,Ogre::String imageSetName);

	std::string getSelectedListItem(const CEGUI::EventArgs& e,std::string windowName);



	bool isCheckBoxSelected(std::string checkBoxName);
};



#endif